package com.sky.mapper;/*
 * ClassName: addressBookServiceMapper
 * Package : com.sky.mapper
 * Description:
 * @Author zKer
 * @Create 2024/4/19 12:41
 */

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    List<AddressBook> selectList(AddressBook addressBook);

    @Insert("insert into address_book( user_id, consignee, sex, phone, province_code, province_name, city_code," +
            " city_name, district_code, district_name, detail, label, is_default)" +
            " VALUES (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName}," +
            "#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void insert(AddressBook addressBook);

    @Select("select * from address_book where id = #{id}")
    AddressBook selectById(Long id);

    void update(AddressBook addressBook);

    @Update("update address_book set is_default = 0 where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
